import Vue from 'vue'
import Vuex from 'vuex'
import {ADD_SUBSCRIPT_CATEGORY, SUCCESS} from "./mutaions_type"
import { ADDREAD } from "./mutaions_type"
import { CHANGE_SUBSCRIPT_CATEGORY } from "./mutaions_type"
import {LIST_SUBSCRIPT_CATEGORY} from "../constants/action-types";
import {subscriptionList} from "../api/CMS-api";
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    Whether:"",
    readNum:0,
    subscriptionCategoryList: []
  },
  mutations: {
    [SUCCESS](state,payload){
      state.Whether = payload.Whether;
    },
    [ADDREAD](state,payload){
      state.readNum = payload.readNum
    },
    [CHANGE_SUBSCRIPT_CATEGORY](state,payload){
      state.subscriptionCategoryList = payload.subscriptionCategoryList
    },
    [ADD_SUBSCRIPT_CATEGORY](state, payload) {
      state.subscriptionCategoryList.push(payload.category);
    }
  },
  //异步
  actions: {
    [LIST_SUBSCRIPT_CATEGORY](context) {
      subscriptionList().then(res => {
        context.commit(CHANGE_SUBSCRIPT_CATEGORY, {
          subscriptionCategoryList: res.rows
        })
      })
    }
  },
  modules: {
  }
})


